<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>
    // 编写函数，生成十六进制的随机颜色值
    function randomColor16(){
        // "#1a2b3c"
        // "#" + "0f" + "2b" + "3c"

                //    15          f

        var r = createZero(random(0,255).toString(16));
        var g = createZero(random(0,255).toString(16));
        var b = createZero(random(0,255).toString(16));

        return "#" + r + g + b;

    }
    console.log(randomColor16());

    function createZero(n){
        // if(n.length < 2){
        //     return "0" + n;
        // }else{
        //     return n;
        // }
        return n.length<2 ? "0"+n : n;
    }


    function random(a,b){
        return Math.round(Math.random()*(a-b)+b)
    }

</script>
</html>